package GUI;

/**
 * Statistical report for the principle 
 * the principle selects a class to get 
 * grades between all teachers that teach this class
 */

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import Common.*;


public class StatRepBTeachers4Grade extends JPanel {
	private JLabel lblHistogram = null;
	private JLabel lblSelectClass = null;
	private JButton btnShowReport = null;
	private JComboBox selClassCb = null;
	
	public Login myLoginFrame = null;
	public UserPrinciple user;
	public PrincipleMainMenu prmn = null;
	
	private String selClass = null;
	private Histogram4StatBTeacher4Class his = null;
	
	
	public JComboBox getSelClassComboBox(final PrincipleMainMenu prmn)
	{
		if(selClassCb==null)
		{
			selClassCb = new JComboBox(prmn.user.Classes);
			selClassCb.setBounds(167, 80, 208, 22);
			selClassCb.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					selClass = selClassCb.getSelectedItem().toString();
					prmn.user.setSelClass(selClass);
					System.out.println(selClass);
				

				}
			});
		}
		
		return selClassCb;
		
	}
	
	public JButton getShowReportBtn(final PrincipleMainMenu prmn)
	{
		if(btnShowReport==null)
		{
			btnShowReport = new JButton("Show report");
			btnShowReport.setBounds(596, 254, 93, 23);
			btnShowReport.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
						
					
					his=null;
					
					//String[] temp = selClass.split(" ");
					//cid = temp[2];
					System.out.println(prmn.user.getSelClass());
					user.dataHistograms.BTeachForClass=null;
					myLoginFrame.client.handleMessageFromClientUI("DataForHistBetweenTeachersInChosenClass "+prmn.user.getSelClass());
					while(user.dataHistograms.BTeachForClass==null);
					
					
				
					his  = prmn.getHistogramT4C(prmn.user.dataHistograms.BTeachForClass.size());
					System.out.println("trying to set size");
					System.out.println("size is: "+prmn.user.dataHistograms.BTeachForClass.size());
					
					
					his.showHistogram();
					//prmn.setContentPane(his);
					//TODO show all the courses that the student isnt registered to and he graduated from the intro courses needed to study this courses
				
			}
		});
			
			
		}
		return btnShowReport;
	}
	
	private void initialize(PrincipleMainMenu prmn)
	{
		setLayout(null);
		
		 lblHistogram = new JLabel("Histogram of grades between teachers for one class ");
		lblHistogram.setBounds(10, 11, 254, 14);
		add(lblHistogram);
		
		lblSelectClass = new JLabel("Select Class:");
		lblSelectClass.setBounds(49, 84, 75, 14);
		add(lblSelectClass);
		
		add(getSelClassComboBox(prmn));
		
		add(getShowReportBtn(prmn));
		
	}
	
	
	public StatRepBTeachers4Grade(PrincipleMainMenu prmn) {
		super();
		initialize(prmn);
		
	}
}
